#python爬取的类型:str,bytes
#爬取的是bytes:写入需要字符串,decode('utf-8')
#爬取的是str:写入的是bytes,encode('utf-8')
import urllib.request
import urllib.parse
import string
def get_method_params():
    url='https://www.baidu.com/s?wd='
    #拼接字符串
    name='美女'
    final_url=url+name
    name=urllib.parse.quote(name)
    final_url1=url+name
    #print(final_url)
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'
    }
    encode_new_url=urllib.parse.quote(final_url,safe=string.printable)
    print(encode_new_url)
    request=urllib.request.Request(final_url1,headers=headers)
    reponse=urllib.request.urlopen(request)
    print(reponse.read().decode('utf-8'))
get_method_params()
